//加载公共样式
require('../../assets/css/public.less')

//加载自己的样式
require('./circle.less')
// 引入aioxs
const request = require('../../lib/request/request')
// 服务器地址
const API = 'http://fitness.h5.itsource.cn:3701'
//引入tabbar渲染函数
const renderTabbar = require('../../lib/tabbar/tabbar')
window.onload = () => {
    //渲染tabbar
    renderTabbar('circle')

    // 获取数据
    function getData() {

        request.get('/api/train/courseList').then(res => {
            // 解构
            let { errno, data } = res.data
            // console.log(res.data);
            // 判断
            if (errno === 0) {
                console.log('data :>> ', data);
                // 渲染
                render(data)
            }
        })
        request.get('/api/circles/opinionList').then(res => {
            let { errno, data } = res.data
            if (errno === 0) {
                console.log('res.data :>> ', res.data);
                // 渲染
                let dd = res.data.data
                xuan(dd)


            }
        })
        request.get('/api/user/info').then(res => {
            let { errno, data } = res.data
            if (errno === 0) {
                console.log('res.data :>> ', res.data);
                // 渲染
                let d1 = res.data.data
                x(d1)
            }
        })
    }
    getData()

    // 渲染
    // 推荐课程
    function render(data) {
        // console.log(data[0]);
        let html = `
        <p class="newclass">推荐课程</p>
            <a href="./courseDetail.html?id=${data[0].courseId}" class="bigout">
                <img class="img" id="img" src="${API + data[0].imgurl}">
                <p id="tit">${data[0].name}</p>
                <p id="content">${data[0].desc}</p>
            </a>
        `
        newCourse.innerHTML = html
    }
    function x(data) {
        let html = `
                <img src="${API + data.imgUrl}" id="touxiang">
                <div class="r df fdc jcc">
                    <p>${data.nickName}</p>
                    <div id="citt">
                    <span class="address">四川省，成都市</span>
                    </div>
                </div>
        `
        yonghu.innerHTML = html
    }

    function aa(data) {
        let html = `
        <span class="address">${data.provinceId}省，${data.cityId}市</span>
        `
        citt.innerHTML = html
    }
    function xuan(data) {
        let html =
            `
            <p id="content">${data[0].content}</p>
            <div class="pho df fww jcsa">
                <img src="${API + data[1].imgUrls}" alt="">
                <img src="${API + data[2].imgUrls}" alt="">
                <img src="${API + data[3].imgUrls}" alt="">
                <img src="${API + data[0].imgUrls}" alt="">
                <img src="${API + data[4].imgUrls}" alt="">
                <img src="${API + data[5].imgUrls}" alt="">
            </div>
            `
        user.innerHTML = html
    }

}

